package com.jilintongyi.jlcrtvu.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.jilintongyi.jlcrtvu.entity.SysUser;

/**
 * 用户详情服务接口实现类
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
	@Autowired
	private UserServiceImpl userService;

	/**
	 * 根据用户名查找用户
	 */
	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		SysUser user = userService.findByUsername(username);
		if (user == null || user.getDeleted()) {
			throw new UsernameNotFoundException(username);
		}
		return user;
	}
}
